<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.js"></script>
    <script type="text/javascript" src="../js/respond.min.js"></script>
    <![endif]-->
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="../css/H-ui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../css/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../js/jqueryPagination/jquery.pagination.css"/>
    <title>用户管理</title>
    <style>
        select {
            height: 31px;
        }
    </style>
</head>
<body>
<nav class="breadcrumb">

    <i class="Hui-iconfont">&#xe67f;</i>
    首页 <span class="c-gray en">&gt;</span>
    用户管理 <span class="c-gray en">&gt;</span>
    用户信息 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
            href="javascript:location.replace(location.href);" title="刷新">
    <i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
    <input type="hidden" id="pageNum" data="data-pageNum"/>

    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量删除</a>
        </span>

    </div>
    <div>
        <div class="condition-row clearfix pd-5">
            <div class="fl paLeft">
                <input type="text" name="name" id="name" placeholder="请输入用户姓名" class="input-text"
                       onblur="replaceSpace(this.value,this.id)">
            </div>
            <div class="fl paLeft">
                <input type="text" name="account" id="account" placeholder="请输入登录账号" class="input-text"
                       onblur="replaceSpace(this.value,this.id)">
            </div>
            <div class="fl paLeft">
                <select name="enabled" id="enabled" style="width: 110px;">
                    <option value="">请选择是否可用</option>
                    <option value="1">启用</option>
                    <option value="0">停用</option>
                </select>
            </div>
            <div class="btn btn-success radius searchBtn" onclick="getData(0)">搜索</div>
        </div>
    </div>
    <div>
        <form action="" id="search" class="hidden">
            <input type="text" value="" name="userId"/>
        </form>
        <input type="hidden" id="userId" data-userid=""/>
        <input type="hidden" id="query" data-userid="" data-iftrue=""/>
    </div>
    <table class="table table-border table-bordered table-hover table-bg table-sort ">
        <thead>
        <tr>
            <th scope="col" colspan="10">用户列表<span class="r">共有数据：<strong class="total"></strong> 条</span></th>
        </tr>
        <tr class="text-c">
            <th><input type="checkbox" value="" name=""></th>
            <th>用户姓名</th>
            <th>登录账号</th>
            <th>手机号</th>
            <th>是否超级管理员</th>
            <th>是否有复核人权限</th>
            <th>是否可用</th>
            <th>角色</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody class="tableCon">

        </tbody>
    </table>
    <div id="PaginationListTop1" class="page">
        <div id="PaginationList1" class="page-wrap" style="">
            <div id="Pagination"></div>
        </div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../js/H-ui.js"></script>
<script type="text/javascript" src="../js/H-ui.min.js"></script>
<script type="text/javascript" src="../js/postJson.js"></script>
<script type="text/javascript" src="../js/root.js"></script>
<script type="text/javascript" src="../js/jqueryPagination/jquery.pagination.min.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../js/jquery.contextmenu.r2.js"></script>
<script type="text/javascript">

    function getData(pageNo) {
        var pageNum = pageNo == 0 ? 1 : pageNo;
        var pageSize = 10;
        var name = $("#name").val();
        var account = $("#account").val();
        var enabled = $("#enabled option:selected").val();
        var jsonObj = {
            "name": name,
            "account": account,
            "enabled": enabled,
            "pageNo": pageNum,
            "pageSize": pageSize
        }
        var jsonData = JSON.stringify(jsonObj)
        var url = "/sysUser/usersList";
        $.ajax({
            url: url,
            contentType: "application/json",
            data: jsonData,
            type: "post",
            async: false,
            dataType: 'json',
            success: function (msg) {
                $(".tableCon ").empty();
                // console.log(JSON.stringify(msg))
                var htmlString = '';
                $(".total").text(msg.data.total)
                if (msg.data.list.length != 0) {
                    $.each(msg.data.list, function (i, n) {
                        htmlString += '<tr class="text-c" roleid="' + n.id + '">'
                        htmlString += '<td><input type="checkbox" value="" name="" raleid = "' + n.id + '"></td>'
                        htmlString += '<td>' + n.name + '</td>'
                        htmlString += '<td>' + n.account + '</td>'
                        htmlString += '<td>' + n.mobile + '</td>'
                        if (n.superAdmin == 1) {
                            htmlString += '<td>是</td>'
                        } else {
                            htmlString += '<td>否</td>'
                        }
                        if(n.checkManager == 1){
                            htmlString += '<td>是</td>'
                        }else{
                            htmlString += '<td>否</td>'
                        }
                        if (n.enabled == 1) {
                            htmlString += '<td>是</td>'
                        } else {
                            htmlString += '<td>否</td>'
                        }
                        htmlString += '<td>'
                        htmlString += '<a class="btn btn-danger radius" superAdmin="' + n.superAdmin + '" raleid = "' + n.id + '" onclick="user_query(' + "\'角色查看\'" + ',' + "\'toQueryUser\'" + ',' + 400 + ',' + 350 + ',' + n.id + ',' + n.superAdmin + ')">查看</a>'
                        htmlString += '</td>'
                        htmlString += '<td>' + TimeHours(n.createTime)  + '</td>'
                        htmlString += '<td>'
                        htmlString += '<a title="编辑" raleId = "' + n.id + '" href="javascript:;" onclick="user_update_edit(' + "\'用户修改\'" + ',' + "\'toUpdateUser'" + ',' + n.id + ',' + 1000 + ',' + 550 + ',' + (msg.data.pageNum) + ')"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="user_del(this,' + n.id + ',' + (msg.data.pageNum) + ')" class="ml-5"><i class="Hui-iconfont">&#xe6e2;</i></a><a title="重置密码" href="javascript:;" onclick="admin_updata_pass(this,' + n.id + ')" class="ml-5"><i class="Hui-iconfont">&#xe63f;</i></a>'
                        htmlString += '</td>'
                        htmlString += '</tr>'
                    })
                } else {
                    htmlString += '<tr class="text-c"><td colspan="10">没有找到匹配的记录</td></tr>'
                }

                $(".tableCon ").append(htmlString)

                var newPageNo = pageNo == 0 ? 1 : pageNo;
                //翻页
                $("#Pagination2").pagination({
                    currentPage: newPageNo,
                    totalData: msg.data.total,
                    totalPage: msg.data.pages,
                    isShow: true,
                    count: 4,
                    showData: pageSize,
                    homePageText: "首页",
                    endPageText: "尾页",
                    prevPageText: "上一页",
                    nextPageText: "下一页",
                    callback: getData
                });
                $("input[placeholder='页码']").css({
                    "border": "solid 1px #c5b7b7"
                })
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var XmlStatus = XMLHttpRequest.status
//                         console.log(XMLHttpRequest.status)
                if (XmlStatus == 401) {
                    alert(XmlError.error401)
                    parent.window.location.href = "../login.html"
                }
                if (XmlStatus == 403) {
                    alert(XmlError.error403)
                }
            }
        })
    }
    getData(0)

    //    alert(parent.$("#iframe_box").attr("data-userid"))
    var parentUserId = parent.$("#iframe_box").attr("data-userid")

    /*管理员-添加用户*/
    function user_add(title, url, w, h) {
        layer_show(title, url, w, h);
    }
    /*管理员-查询*/
    function user_query(title, url, w, h, id, superM) {
        $("#query").attr("data-userid", id)
        $("#query").attr("data-iftrue", superM)
        layer_show(title, url, w, h);
    }
    /*用户管理-用户信息-密码重置*/
    function admin_updata_pass(obj, userId) {
        var dataCollect = "id=" + userId;
        dataCollect = decodeURIComponent(dataCollect, true);//防止中文乱码
        var jsondata = strJSON.formToJson(dataCollect);//转化为json
        var url = "/sysUser/resetPwd";
        layer.confirm('确认要重置密码吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                contentType: "application/json",
                data: jsondata,
                dataType: 'json',
                success: function (msg) {
                    if(msg.success){
                        layer.msg("重置密码为：" + msg.data, {icon: 1, time: 3000});
                    }else {
                        var error = msg.errorMessage;
                        parent.layer.msg(error,{icon:2,time:3000});
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    var XmlStatus = XMLHttpRequest.status
//                         console.log(XMLHttpRequest.status)
                    if (XmlStatus == 401) {
                        alert(XmlError.error401)
                        parent.window.location.href = "../login.html"
                    }
                    if (XmlStatus == 403) {
                        alert(XmlError.error403)
                    }
                }
            });
        });
    }

    /*批量删除*/
    function datadel() {

        var arrDel = [];
        var allUserId = ''
        $(".tableCon tr").each(function () {
            if ($(this).find("td:first input:checked").length != 0) {
                allUserId += $(this).find("td:first input:checked").attr("raleid") + ","
                arrDel.push($(this).find("td:first input:checked").attr("raleid"))
            }
        })
        var strArr = String(allUserId.substring(0, allUserId.length - 1))
        var dataCollect = "allUserId=" + strArr;
        dataCollect = decodeURIComponent(dataCollect, true);//防止中文乱码
        var jsondata = strJSON.formToJson(dataCollect);//转化为json
        var url = "/sysUser/deleteUserAll";
        if (arrDel.length != 0) {
            layer.confirm('角色删除须谨慎，确认要删除吗？', function (index) {
                $.ajax({
                    type: 'POST',
                    url: url,
                    contentType: "application/json",
                    data: jsondata,
                    dataType: 'json',
                    success: function (data) {
                        if (data.success == true) {
                            for (var i = 0; i < arrDel.length; i++) {
                                $(".tableCon tr").each(function () {
                                    if ($(this).find("td:first input:checked").attr("raleid") == arrDel[i]) {
                                        $(this).remove()
                                    }
                                })
                            }
                            layer.msg('已删除!', {icon: 1, time: 3000});
                            window.location.reload();
                        } else {
                            for (var i = 0; i < arrDel.length; i++) {
                                $(".tableCon tr").each(function () {
                                    if ($(this).find("td:first input:checked").attr("raleid") == arrDel[i]) {
                                        $(this).remove()
                                    }
                                })
                            }
                            layer.msg('登录用户与所选用户相同，不能删除!', {icon: 1, time: 4000});
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        var XmlStatus = XMLHttpRequest.status
//                         console.log(XMLHttpRequest.status)
                        if (XmlStatus == 401) {
                            alert(XmlError.error401)
                            parent.window.location.href = "../login.html"
                        }
                        if (XmlStatus == 403) {
                            alert(XmlError.error403)
                        }
                    }
                });
            });
        } else {
            layer.msg('请选择需要删除的用户!', {icon: 1, time: 3000});
        }

    }
    /*管理员-修改*/
    function user_update_edit(title, url, id, w, h, pageNum) {
        $("#userId").attr("data-userid", id);
        $("#pageNum").attr("data-pageNum", pageNum);
        layer_show(title, url, w, h);
    }


    /*用户管理-角色信息-删除*/
    function user_del(obj, userId, pageNum) {
        var dataCollect = "id=" + userId;
        dataCollect = decodeURIComponent(dataCollect, true);//防止中文乱码
        var jsondata = strJSON.formToJson(dataCollect);//转化为json
        // console.log(jsondata)
        var url = "/sysUser/deleteUser";
        layer.confirm('用户删除须谨慎，确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                contentType: "application/json",
                data: jsondata,
                dataType: 'json',
                success: function (data) {
                    if (data.success == true) {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {icon: 1, time: 3000});
                        getData(pageNum);
                    } else {
                        layer.msg('登录用户与所选用户相同，不能删除!', {icon: 1, time: 3000});
                    }
                },

                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    var XmlStatus = XMLHttpRequest.status
//                         console.log(XMLHttpRequest.status)
                    if (XmlStatus == 401) {
                        alert(XmlError.error401)
                        parent.window.location.href = "../login.html"
                    }
                    if (XmlStatus == 403) {
                        alert(XmlError.error403)
                    }
                }
            });
        });
    }
    $(".tableCon tr").each(function () {
        if ($(this).attr("roleid") == parentUserId) {
            $(this).find("td:first input").attr("data-mark", true)
            $(this).find("td:first input").bind("click", function () {
                $(this).prop("checked", false)
                layer.msg('登录用户与所选用户相同，不能删除!', {icon: 1, time: 3000});
            })
        }
    })

</script>
</body>
</html>